import clientEnum from "./client.enum"
import clientFunc from "./client.func"

export default class CylinderSource {
  id: any
  updateSourceCall: any
  userData: any
  volumeCache: { basePoint: { x: number; y: number; z: number }; height: number; radius: number }
  constructor(t, e, s, i) {
    this.id = t
    this.updateSourceCall = e
    this.userData = s
    this.volumeCache = { basePoint: { x: 0, y: 0, z: 0 }, height: 1 / 0, radius: 1 / 0 }
    this.updateCache(i.basePoint, i.height, i.radius)
  }
  get facade() {
    const t = {
      basePoint: Object.assign({}, this.volumeCache.basePoint),
      height: this.volumeCache.height,
      radius: this.volumeCache.radius
    }
    const e = this,
      s = new (class CylinderFacade {
        get type() {
          return clientEnum.ct.CYLINDER
        }
        get volume() {
          return t
        }
        get userData() {
          return e.userData
        }
        commit() {
          e.commit(this)
        }
      })()
    return clientEnum.ot.map.set(s, this), s
  }
  commit(t) {
    this.hasSourceChanged(t) &&
      (this.updateCache(t.volume.basePoint, t.volume.height, t.volume.radius), this.updateSourceCall(this.id, clientEnum.ct.CYLINDER, this.volumeCache))
  }
  hasSourceChanged(t) {
    return !(
      this.volumeCache.basePoint.x === t.volume.basePoint.x &&
      this.volumeCache.basePoint.y === t.volume.basePoint.y &&
      this.volumeCache.basePoint.z === t.volume.basePoint.z &&
      this.volumeCache.height === t.volume.height &&
      this.volumeCache.radius === t.volume.radius
    )
  }
  updateCache(t, e, s) {
    clientFunc.P(this.volumeCache.basePoint, t), (this.volumeCache.height = e), (this.volumeCache.radius = s)
  }
}
